package com.mikepenz.app.activity.card;

import android.app.ProgressDialog;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mikepenz.app.R;
import com.mikepenz.bean.CardBean;
import com.mikepenz.presenter.CardMyPresenter;
import com.mikepenz.presenter.ScanPresenter;
import com.mikepenz.presenter.imp.CardMyPresenterImp;
import com.mikepenz.presenter.imp.ScanPresenterImp;
import com.mikepenz.view.CardMyView;
import com.mikepenz.view.ScanView;
import com.quickdv.activity.BaseActivity;
import com.quickdv.until.AlertHelper;

import butterknife.InjectView;

/**
 * 我的卡片中心
 */
public class MyCardActivty extends BaseActivity implements CardMyView,ScanView,View.OnClickListener{

    ProgressDialog dialog;
    CardMyPresenter presenter;
    @InjectView(R.id.card_name)
    TextView cardName;
    @InjectView(R.id.card_money)
    TextView cardMoney;
    @InjectView(R.id.card_select)
    RelativeLayout cardSelect;
    @InjectView(R.id.card_recharge)
    LinearLayout cardRecharge;
//    @InjectView(R.id.card_cost)
//    LinearLayout cardCost;
    @InjectView(R.id.card_binder)
    LinearLayout cardBinder;
    private ScanPresenter presenter2;


    @Override
    public int getLayoutID() {
        return R.layout.activity_my_card_activty;
    }

    @Override
    public void initView() {

    }


    @Override
    public void initActionbar() {

    }

    @Override
    public void initData() {
        presenter= new CardMyPresenterImp(this);
        presenter2 = new ScanPresenterImp(this);
        AlertHelper helper = new AlertHelper(this);
        dialog = helper.LoadingAlert();
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.initViewAndEvent();
    }

    @Override
    public void initViewAndEvent(CardBean bean) {

        cardName.setText("卡号:"+ bean.getCardCode());
        cardMoney.setText("余额:" + bean.getMoney() + "元");
        cardMoney.setVisibility(View.VISIBLE);


//        cardCost.setOnClickListener((View.OnClickListener) presenter);
        cardRecharge.setOnClickListener(this);
        cardSelect.setOnClickListener(this);
        cardBinder.setOnClickListener(this);


    }

    @Override
    public void initBinder() {
        cardBinder.setOnClickListener(this);
    }


    @Override
    public void showLoad() {
        if (dialog != null)
            dialog.show();
    }

    @Override
    public void dismissLoad() {
        if (dialog != null) dialog.dismiss();
    }

    @Override
    public void showError(String error) {
        Toast.makeText(this, error, Toast.LENGTH_LONG).show();
    }

    @Override
    public void refreshDate(CardBean bean) {
        initViewAndEvent(bean);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 105 && resultCode== 200){
            String cardCode = data.getStringExtra("result");
            presenter2.checkCard(cardCode);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onClick(View view) {
        presenter.onClick(view);
    }
}
